<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
  <link rel="stylesheet" href="../css/index.css">
  <link rel="stylesheet" href="../css/orderInfo.css">
  <title>订单信息</title>
</head>

<body class="orderInfo page-group">
  <div class="page">
    <!-- <header class="bar bar-nav" id="golbalHeader"></header> -->
    <!-- 这里是页面内容区 -->
    <div class="content">
      <!-- <div class="pull-to-refresh-layer">
        <div class="preloader"></div>
        <div class="pull-to-refresh-arrow"></div>
      </div> -->
      <div class="buttons-tab">
        <a href="#" data-id="0" class="tab-link active button">全部</a>
        <a href="#" data-id="3" class="tab-link button">待支付</a>
        <a href="#" data-id="1" class="tab-link button">已支付</a>
      </div>

      <div class="content-block">
        <div class="card-content">
          <div class="list-block media-list">
            <ul class="orderList">
            </ul>
            <p class="moreInfo" onclick="orderInfo.loadMore()">正在加载数据</p>
          </div>
        </div>
      </div>
    </div>

    <!-- 底部 -->
    <div id="modal">
      <li class="item-content" onclick="orderInfo.goPay(this)">
        <div class="item-media">
          <img src="" width="44">
        </div>
        <div class="item-inner">
          <div class="item-title-row">
            <div class="item-title relative" style="width:100%;">
              <span class="name"></span>
              <span class="payStatus absolute">待支付</span>
            </div>
          </div>
          <div class="item-subtitle relative">
            <span class="orderServiceStartTime"></span>
          </div>
          <div class="item-subtitle relative">
            <span class="price"></span>
            <a href="#" class="button button-big button-fill button-success payButton" onclick="orderInfo.goPay(this)">去支付</a>
          </div>
        </div>
      </li>
    </div>
  </div>
  <!-- 标题栏 -->

</body>
<script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
<script type="text/javascript" src="../js/index.js"></script>
<script type="text/javascript">
  var orderInfo = (function ($) {
    $.init()
    var orderInfo = new ST({
      golbalHeaderText: '订单信息',
      golbalHeaderFunc: function () {
        window.history.go(-1)
      },
      getOrderList: {
        page: 1,
        pageSize: 5,
        status: 0
      }
    })
    orderInfo.goPay = function (context) {
      window.location.href = './payOnline.html?orderId=' + $(context).data('orderid')
    }
    orderInfo.loadMore = function () {
      orderInfo.getOrderList.page++
        orderInfo.http('getOrderList')
    }
    orderInfo.pushAjax({
      getOrderList: {
        url: '/app/api/private/order/orderList',
        data: orderInfo.getOrderList
      }
    })
    orderInfo.pushAjaxSuccess({
      getOrderList: function (res) {
        if (res.code === '1') {
          res.data.orderList.forEach(function (ele) {
            var li = $('#modal li').clone()
            $(li).find('.name').text(ele.name)
            $(li).find('img').attr('src', ele.service && ele.service.image || '../image/pay.png')
            $(li).find('.price').text('￥' + ele.payPrice)
            
            if(Number(ele.orderServiceStartTime)){
              $(li).find('.orderServiceStartTime').text(new Date(Number(ele.orderServiceStartTime)).toLocaleString())
            }else{
              $(li).find('.orderServiceStartTime').parent().hide()
            }
            if (ele.status === 1) {
              $(li).find('.payStatus').text('已支付')
              $(li).find('.payButton').hide()
            }
            if (ele.status === 2) {
              $(li).find('.payStatus').text('支付失败')
              $(li).find('.payButton').hide()
            }
            if (ele.status === 3) {
              $(li).find('.payStatus').text('待支付')
              $(li).find('.payButton').show()
            } else if (ele.status === 4) {
              $(li).find('.payStatus').text('已支付')
              $(li).find('.payButton').hide()
            }
            $(li).find('a').attr('data-orderid', ele.orderId)
            $(li).attr('data-orderid', ele.orderId)
            $(li).appendTo($('ul.orderList'))

          })
          if (res.data.orderList.length < 5) {
            $('.moreInfo').text('没有更多数据')
          } else {
            $('.moreInfo').text('点击加载更多')
          }
        }
      }
    })

    $('.buttons-tab a').on('click', function () {
      $(this).addClass('active').siblings().removeClass('active')
      $('.orderList li').remove()
      $('.moreInfo').text('正在加载数据')
      orderInfo.getOrderList.page = 1
      orderInfo.getOrderList.status = $(this).data('id')
      orderInfo.http('getOrderList')
    })
    orderInfo.render()
    orderInfo.http('getOrderList')
    return orderInfo
  })($)
</script>

</html>